<?php
$conn = mysqli_connect('localhost' , 'root' , 'weicedbmojito160824','weixin_didao_wxapp');
$query = "Set Names 'utf8mb4'";
mysqli_query($conn,$query);

$list = array();
if(isset($_GET['openid']) && $_GET['jyj']==='jyj') {
    $openid = $_GET['openid'];
    $query = "SELECT b.id,b.begin_time_unix,b.`name`,b.location,b.attender_num
            FROM didao_wxapp_party_attender a
            LEFT JOIN didao_wxapp_party b
            ON a.party_id= b.id
            WHERE a.openid = '$openid' AND b.begin_time_unix>UNIX_TIMESTAMP()  AND b.status = 1 AND a.cancel_flag = 1
            ORDER BY b.begin_time_unix ASC
            ";
    $result = mysqli_query($conn,$query);

    while ($row = mysqli_fetch_assoc($result)){
        $row2=substr($row['location'],1,strlen($row['location'])-2);
        $row2=json_decode($row2,true);

        $list['wait'][] = array(
            'partyId' => $row['id'],
            'beginTime' => date('Y年m月d日',$row['begin_time_unix']),
            'title' => $row['name'],
            'location'=>$row2['address'],
            'attend_num'=>$row['attender_num']
        );
    }
    $query = "SELECT b.id,b.begin_time_unix,b.`name`,b.location,b.attender_num
            FROM didao_wxapp_party_attender a
            LEFT JOIN didao_wxapp_party b
            ON a.party_id= b.id
            WHERE a.openid = '$openid' AND b.begin_time_unix<UNIX_TIMESTAMP()  AND b.status = 1 AND a.cancel_flag = 1
            ORDER BY b.begin_time_unix DESC
            ";
    $result = mysqli_query($conn,$query);

    while ($row = mysqli_fetch_assoc($result)){
        $row2=substr($row['location'],1,strlen($row['location'])-2);
        $row2=json_decode($row2,true);
        $list['finish'][] = array(
            'partyId' => $row['id'],
            'beginTime' => date('Y年m月d日',$row['begin_time_unix']),
            'title' => $row['name'],
             'location'=>$row2['address'],
            'attend_num'=>$row['attender_num']
        );
    }
    $query = "SELECT b.id,b.begin_time_unix,b.`name`,b.location,b.attender_num
            FROM didao_wxapp_party_attender a
            LEFT JOIN didao_wxapp_party b
            ON a.party_id= b.id
            WHERE a.openid = '$openid' AND (b.status = '-1' OR a.cancel_flag = '-1')
            ORDER BY b.begin_time_unix DESC
            ";
    $result = mysqli_query($conn,$query);

    while ($row = mysqli_fetch_assoc($result)){
        $row2=substr($row['location'],1,strlen($row['location'])-2);
        $row2=json_decode($row2,true);
        $list['cancel'][] = array(
            'partyId' => $row['id'],
            'beginTime' => date('Y年m月d日',$row['begin_time_unix']),
            'title' => $row['name'],
            'location'=>$row2['address'],
            'attend_num'=>$row['attender_num']
        );
    }
    $list['query'] ="SELECT b.id,b.begin_time_unix,b.`name`,b.location,b.attender_num
            FROM didao_wxapp_party_attender a
            LEFT JOIN didao_wxapp_party b
            ON a.party_id= b.id
            WHERE a.openid = '$openid' AND b.begin_time_unix>UNIX_TIMESTAMP()  AND b.status = 1 AND a.cancel_flag = 1
            ORDER BY b.begin_time_unix ASC
            ";
    echo json_encode($list,JSON_UNESCAPED_UNICODE);

}
/**
 * Created by PhpStorm.
 * User: a7849
 * Date: 2017/7/17
 * Time: 15:42
 */